from common import pagedriver
from page.HomePage import HomePage
from page.LoginPage import LoginPage
from page.LoginandRegisterPage import LoginandRegisterPage
from page.MyPage import MyPage
from page.verifyPage import verifyPage
def login(casename, casedata, assertstr, n):
    # casename:用例名称
    # casedata:用例数据
    # assertstr：断言元素
    # n：n=1，则断言元素能找到则算通过，n若不等于1，则找不到该断言元素才算通过
    print(casename)
    # 输出用例名称
    HomePage().disallow_click()  # 点击“不允许”
    HomePage().my_click()  # 点击“我的”
    MyPage().loginandRegister_click()  # 点击“注册/登录”
    LoginandRegisterPage().login_click()  # 点击“登录”
    LoginPage().input_address(casedata)  # 输入测试公链值
    try:
        LoginPage().login_click()  # 尝试点击“登录账号”
    except:
        pass  # 如果找不到就跳过
    try:
        verifyPage().verify_click()  # 尝试点击“验证地址”
    except:
        pass
    if n == 1:
        print(1)
        try:
            pagedriver.locater_Xpath(assertstr)#寻找断言元素
            bool = True
        except:
            bool = False
    else:
        print(0)
        try:
            pagedriver.locater_Xpath(assertstr)
            bool = False
        except:
            bool = True
    return bool

